package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.vo.BusContactsUnitVo;
import com.drug.wms.domain.BusContactsUnit;
import com.drug.wms.service.IBusContactsUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 往来单位Controller
 * 
 * @author wjZhao
 * @date 2021-11-13
 */
@RestController
@RequestMapping("/wms/contactsunit")
public class BusContactsUnitController extends BaseController
{
    @Autowired
    private IBusContactsUnitService busContactsUnitService;

    /**
     * 查询往来单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusContactsUnit busContactsUnit)
    {
        startPage();
        List<BusContactsUnit> list = busContactsUnitService.selectBusContactsUnitList(busContactsUnit);
        return getDataTable(list);
    }

    /**
     * 导出往来单位列表
     */
    @Log(title = "往来单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusContactsUnit busContactsUnit)
    {
        List<BusContactsUnit> list = busContactsUnitService.selectBusContactsUnitList(busContactsUnit);
        ExcelUtil<BusContactsUnit> util = new ExcelUtil<BusContactsUnit>(BusContactsUnit.class);
        return util.exportExcel(list, "往来单位数据");
    }

    /**
     * 获取往来单位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(busContactsUnitService.selectBusContactsUnitById(id));
    }

    /**
     * 新增往来单位
     */
    @Log(title = "往来单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusContactsUnitVo busContactsUnitVo)
    {
        return toAjax(busContactsUnitService.insertBusContactsUnit(busContactsUnitVo));
    }

    /**
     * 修改往来单位
     */
    @Log(title = "往来单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusContactsUnitVo busContactsUnitVo)
    {
        return toAjax(busContactsUnitService.updateBusContactsUnit(busContactsUnitVo));
    }

    /**
     * 删除往来单位
     */
    @Log(title = "往来单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busContactsUnitService.deleteBusContactsUnitByIds(ids));
    }
}
